<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>{{ dataOption.student ? dataOption.student.name : '' }}-体检报告</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody" id="popupBody">
        <el-form :model="infoForm" label-width="120px" ref="editForm">
          <el-form-item label="当前出生年月:">
            {{ birthday }}
            <el-button v-if="!birthdayStatus" type="primary" @click="editBirthday=true" plain size="mini" class="ml-20">
              格式错误，重新选择
            </el-button>
          </el-form-item>
          <el-form-item label="选择出生年月:" v-if="editBirthday">
            <el-date-picker type="date"
                            size="small"
                            placeholder="选择日期"
                            v-model="infoForm.birthday"
                            value-format="yyyyMMdd"></el-date-picker>
          </el-form-item>
          <el-form-item label="身高调整类型:" prop="num">
            <el-radio-group v-model="infoForm.height_type">
              <el-radio :label="1">升</el-radio>
              <el-radio :label="2">减</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="身高(cm):" prop="num">
            {{ height }}
            <el-input v-model="infoForm.height" placeholder="身高(cm)可不填" size="small" clearable></el-input>
          </el-form-item>
          <el-form-item label="体重调整类型:" prop="num">
            <el-radio-group v-model="infoForm.weight_type">
              <el-radio :label="1">升</el-radio>
              <el-radio :label="2">减</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="体重(kg):" prop="num">
            {{ weight }}
            <el-input v-model="infoForm.weight" placeholder="体重(kg)可不填" size="small" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="checkEditFn">确定修改</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {studentGrowthOne} from "@/api/admin/development"

export default {
  props: ['visible', 'dataOption'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      birthday: '',
      height: '',
      weight: '',
      infoForm: {
        birthday: '',
        height: '',
        weight: '',
        height_type: 1, //	整型 	必填 	1 	- 	身高调整类型1增加2减少
        weight_type: 1, // 	整型 	必填 	1 	- 	体重调整类型1增加2减少
      },
      birthdayStatus: true,
      editBirthday: false
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        console.log('体检数据：', this.dataOption)
        this.height = this.dataOption.height
        this.weight = this.dataOption.weight
        this.birthdayStatus = this.birthdayResult()
      } else {
        this.editBirthday = false
        this.birthday = ''
        this.height = ''
        this.weight = ''
        this.infoForm = {
          birthday: '',
          height: '',
          weight: '',
          height_type: 1, //	整型 	必填 	1 	- 	身高调整类型1增加2减少
          weight_type: 1, // 	整型 	必填 	1 	- 	体重调整类型1增加2减少
        }
      }
    }
  },
  created() {

  },
  methods: {
    checkEditFn() {
      console.log('infoForm:', this.infoForm)
      let data_ = this.getJson(this.infoForm)
      if (!this.birthdayResult() && !data_.birthday) {
        this.$message.error('该生出生日期格式不正确，请重新选择')
        return
      }
      if (!data_.birthday) {
        data_.birthday = this.birthday
      }
      if (!data_.height) {
        data_.height = 0;
      }
      if (!data_.weight) {
        data_.weight = 0;
      }
      data_.id = this.dataOption.id;
      console.log('data_:', data_)
      this.$confirm('确认修改, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        studentGrowthOne(data_).then(res => {
          console.log(res)
          if(!res.code){
            this.$message.success('设置成功')
            this.$emit('InitFn')
            this.closePOpup()
          }else{
            this.$message.error('修改失败，'+res.msg)
          }
        })
      }).catch(() => {
      });
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    birthdayResult() {
      let data_ = this.getJson(this.dataOption)
      let status = true
      if (data_.student && data_.student.birthday) {
        this.birthday = data_.student.birthday
        if (data_.student.birthday.length !== 8) {
          status = false
        }
      }
      return status
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 500px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


